package com.mlc.mlcfes1;


import it.unimi.dsi.fastutil.ints.IntBigList;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.stream.Collectors;


public class scoretop implements CommandExecutor{
    public final Mlcfes1 plugin; // 你的主插件类

    public scoretop(Mlcfes1 plugin) {
        this.plugin = plugin;
    }
    @Override
    public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String @NotNull [] strings) {
        FileConfiguration file = plugin.getConfig();
        ConfigurationSection playername = file.getConfigurationSection("Data");
        Map<String , Integer> map = new HashMap<>();;
        for(String player : playername.getKeys(false))
        {
            String name = "Data." + player;
            int a = file.getInt(name + ".score");
            map.put(player,a);
        };
        List<Map.Entry<String, Integer>> list = new ArrayList<>(map.entrySet());
        list.sort((e1, e2) -> e2.getValue().compareTo(e1.getValue()));

        int num = 0;
        for(Map.Entry<String, Integer> entry : list)
        {
            if(num>3)
            {
                break;
            }
            commandSender.sendMessage(entry.getKey() + ":" + entry.getValue());
            num++;
        }
        return false;
    }
}
